<template>
  <div class="box_search">
    <el-input v-model="name" placeholder="请输入关键字" class="input-with-select">
      <template slot="prepend">
        <div style="font-weight: bolder; color: #42b983">关键字搜索</div>
      </template>
      <el-button slot="append" icon="el-icon-search" @click="searchData" />
    </el-input>
    <el-dialog
      :showClose="false"
      title="关键字搜索"
      :visible.sync="dialogVisible"
      width="60%"
    >
      <div style="margin: 0 auto">
        <el-input v-model="name" style="margin-bottom: 20px" placeholder="请输入关键字" class="input-with-select">
          <template slot="prepend">
            <div style="font-weight: bolder; color: #42b983">关键字搜索</div>
          </template>
          <el-button slot="append" icon="el-icon-search" @click="searchData" />
        </el-input>
        <Table
          ref="table"
          :table-data="tableData"
          :if-pagination="true"
        >
          <el-table-column
            slot="action"
            align="center"
            fixed="right"
            label="操作"
            width="240"
          >
            <template slot-scope="scope">
              <el-tooltip content="查看此记录" placement="bottom">
                <el-button icon="el-icon-postcard" size="mini" type="success" @click="queryDetail(scope.row)" />
              </el-tooltip>
              <el-tooltip v-if="!farmId && !scope.row.ifUpdate" content="修改此记录" placement="bottom">
                <el-button size="mini" type="primary" icon="el-icon-edit" @click="updateDetail(scope.row)" />
              </el-tooltip>
              <el-tooltip
                v-if="!farmId && !scope.row.ifDelete && !scope.row.ifUpdate"
                content="删除此记录"
                placement="bottom"
              >
                <el-button size="mini" type="danger" icon="el-icon-delete" @click="deleteDetail(scope.row)" />
              </el-tooltip>
              <el-tooltip
                v-if="!farmId && scope.row.ifDelete"
                content="报废此记录"
                placement="bottom"
              >
                <el-button
                  :disabled="scope.row.scrap !== 1"
                  size="mini"
                  type="warning"
                  icon="el-icon-warning-outline"
                  @click="scrapDetail(scope.row)"
                />
              </el-tooltip>
            </template>
          </el-table-column>
        </Table>
        <div style="text-align: center; margin-top: 20px">
          <el-button type="primary" @click="open">关 闭</el-button>
        </div>
      </div>
    </el-dialog>
    <!--    新增修改弹窗-->
    <el-dialog
      v-if="dialogVisibleTwo"
      :title="titleInfo"
      :visible.sync="dialogVisibleTwo"
      width="30%"
    >
      <MyForm
        ref="form"
        :file-id="fileId"
        :form="formData.form"
        :inline="false"
        :options="formData.options"
        :rules="formData.rules"
        :label-width="formData.labelWidth"
        @validate="validate"
        @clearValidate="clearValidate"
      />
    </el-dialog>
  </div>
</template>

<script>
import Table from '../table/index'
import MyForm from '../form/form'
import { queryAllByName } from '@/api/bookkeepingQuery'
import publicDataQuery from '@/utils/publicDataQuery.json'
import publicDataUpdate from '@/utils/publicDataUpdate.json'
import { formatData, formatDataB, testNumber } from '@/utils/common'
import {
  deleteExpensesRecord,
  deleteIncomeRecord,
  deleteStockRecord,
  updateExpensesRecord,
  updateIncomeRecord, updateStockRecord
} from '@/api/stock'
import { MessageBox } from 'element-ui'
import { deleteCreditDebtRecord, updateCreditDebtRecord } from '@/api/creditorDebts'

export default {
  name: 'SearchForm',
  components: {
    Table,
    MyForm
  },
  props: {
    farmId: {
      type: String
    }
  },
  data() {
    return {
      titleInfo: '',
      name: '',
      dialogVisible: false,
      dialogVisibleTwo: false,
      creator: '',
      // 表格默认字段
      tableData: {
        columns: [
          // {
          //   selection: true
          // },
          {
            index: true,
            indexMethod(index) {
              return index + 1
            }
          },
          {
            prop: 'type',
            label: '类别'
          },
          {
            prop: 'name',
            label: '名称'
          },
          {
            prop: 'amount',
            label: '金额(元)/数量'
          },
          {
            prop: 'occurDate',
            label: '日期'
          },
          {
            slot: 'action'
          }
        ],
        data: [],
        total: 0
      },
      // form表单
      formData: {},
      ledgerIdOne: '',
      ledgerIdTwo: '',
      id: '',
      fileId: [],
      amount: '',
      currentAmount: ''
    }
  },
  methods: {
    // 搜索
    searchData() {
      if (!this.name) {
        this.$message.error('请输入查询条件')
        return
      }
      this.dialogVisible = true
      queryAllByName(this.name, this.farmId).then(res => {
        if (res.code === 0) {
          // console.log(res)
          this.tableData.data = res.result
          this.tableData.data.forEach(v => {
            if (v.details) {
              v.details = JSON.parse(v.details)
            }
            if (v.module === '收入' && v.ledgerIdOne === 6 && v.ledgerIdTwo === 31) {
              v.ifDelete = true
            } else if (v.module === '支出' && v.ledgerIdOne === 2) {
              v.ifDelete = true
            } else {
              v.ifDelete = false
            }
            if ((v.module === '库存' || v.module === '债务债权') && v.modifyFlag === 0) {
              v.ifUpdate = true
            } else {
              v.ifUpdate = false
            }
          })
          this.dialogVisible = true
        }
      })
    },
    // 表单确定按钮
    validate() {
      // console.log(this.formData.form)
      if (this.titleInfo === '修改') {
        // 修改收入支出确定
        if (this.creator === 'income' || this.creator === 'expenses') {
          if (!testNumber(this.formData.form.amount)) {
            this.$message.error('金额必须大于0')
            return
          }
          this.formData.form.occurDate = formatData(this.formData.form.occurDate)
          const params = {
            occurDate: this.formData.form.occurDate, // 日期
            amount: this.formData.form.amount, // 金额
            ledgerIdOne: this.ledgerIdOne, // 一级类别
            ledgerIdTwo: this.ledgerIdTwo, // 二级类别
            id: this.id, // 记录id
            details: this.formData.form
          }
          if (this.creator === 'income') {
            updateIncomeRecord(params).then(res => {
              if (res.code === 0) {
                this.$message.success('修改成功')
                this.searchData()
              }
            })
          } else {
            updateExpensesRecord(params).then(res => {
              if (res.code === 0) {
                this.$message.success('修改成功')
                this.searchData()
              }
            })
          }
        }
        // 修改债权债务确定
        if (this.creator === 'creditor') {
          if (!testNumber(this.formData.form.amount)) {
            this.$message.error('金额必须大于0')
            return
          }
          if (this.formData.form.flag === -1 && (Number(this.formData.form.amount) > (Number(this.amount) + Number(this.currentAmount)))) {
            this.$message.error('合计数为负数，操作失败！')
            return
          }
          if (this.formData.form.fileId) {
            this.formData.form.fileId = this.formData.form.fileId.toString()
          }
          const params = JSON.parse(JSON.stringify(this.formData.form))
          params.occurDate = formatData(params.occurDate)
          if (params.agreedDate) {
            params.agreedDate = formatData(params.agreedDate)
          }
          updateCreditDebtRecord(params).then(res => {
            if (res.code === 0) {
              this.$message.success('修改成功')
              this.searchData()
            }
          })
        }
        // 修改库存确定
        if (this.creator === 'stock') {
          if (!testNumber(this.formData.form.amount)) {
            this.$message.error('数量必须大于0')
            return
          }
          if (this.formData.form.flag === -1 && (Number(this.formData.form.amount) > (Number(this.amount) + Number(this.currentAmount)))) {
            this.$message.error('合计数为负数，操作失败！')
            return
          }
          if (this.formData.form.fileId) {
            this.formData.form.fileId = this.formData.form.fileId.toString()
          }
          const params = JSON.parse(JSON.stringify(this.formData.form))
          params.occurDate = formatData(params.occurDate)
          updateStockRecord(params).then(res => {
            if (res.code === 0) {
              this.$message.success('修改成功')
              this.searchData()
            }
          })
        }
        this.dialogVisibleTwo = false
      } else {
        this.dialogVisibleTwo = false
      }
    },
    // 表单取消按钮
    clearValidate() {
      this.dialogVisibleTwo = false
    },
    // 查看
    queryDetail(row) {
      this.fileId = []
      // console.log(row, '查看')
      this.dialogVisibleTwo = true
      // 查看收入支出
      if (row.module === '收入' || row.module === '支出') {
        if (row.module === '收入') {
          this.titleInfo = '查看收入记录'
          this.creator = 'income'
        }
        if (row.module === '支出') {
          this.titleInfo = '查看支出记录'
          this.creator = 'expenses'
        }
        const details = row.details
        details.amount = row.amount
        details.occurDate = formatDataB(row.occurDate)
        this.fileId = details.fileId
        this.changeFormField(row.ledgerIdOne, row.ledgerIdTwo, this.creator, details)
      }
      // 查看债务债权
      if (row.module === '债务债权') {
        this.titleInfo = '查看债权债务记录'
        if (row.fileId) {
          this.fileId = row.fileId.split(',')
        }
        if (row.flag === -1) {
          const options = [
            {
              title: '发生日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '发生金额(元)',
              key: 'amount',
              type: ['number'],
              rules: true,
              disabled: true
            }
          ]
          this.formData.options = options
        } else if (row.flag === 1) {
          const options = [
            {
              title: '发生日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '发生原因',
              key: 'reason',
              type: ['text'],
              rules: true,
              disabled: true
            },
            {
              title: '发生金额(元)',
              key: 'amount',
              type: ['number'],
              rules: true,
              disabled: true
            }
          ]
          this.formData.options = options
        } else if (row.flag === 0) {
          const options = [
            {
              title: '发生日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '相对人',
              key: 'counterparty',
              type: ['text'],
              rules: true,
              disabled: true
            },
            {
              title: '金额(元)',
              key: 'amount',
              type: ['number'],
              rules: true,
              disabled: true
            },
            {
              title: '约定收款日期',
              key: 'agreedDate',
              type: ['date', 'direction', 1],
              disabled: true
            },
            {
              title: '约定还款日期',
              key: 'agreedDate',
              type: ['date', 'direction', 2],
              disabled: true
            },
            {
              title: '发生原因',
              key: 'reason',
              type: ['text'],
              disabled: true
            },
            {
              title: '附件上传',
              key: 'fileId',
              type: ['file'],
              rules: false,
              disabled: true
            }
          ]
          this.formData.options = options
        }
        this.formData.form = JSON.parse(JSON.stringify(row))
        this.formData.form.occurDate = formatDataB(this.formData.form.occurDate)
      }
      // 查看库存
      if (row.module === '库存') {
        this.titleInfo = '查看库存记录'
        if (row.fileId) {
          this.fileId = row.fileId.split(',')
        }
        if (row.flag === -1) {
          const options = [
            {
              title: '出库日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '出库数量',
              key: 'amount',
              type: ['number'],
              rules: true,
              disabled: true
            },
            {
              title: '出库去向',
              key: 'sourceDisposition',
              type: ['text'],
              rules: true,
              disabled: true
            }
          ]
          this.formData.options = options
        } else if (row.flag === 1) {
          const options = [
            {
              title: '入库日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '入库数量',
              key: 'amount',
              type: ['number'],
              rules: true,
              disabled: true
            }
          ]
          this.formData.options = options
        } else if (row.flag === 0) {
          const options = [
            {
              title: '日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '名称',
              key: 'name',
              type: ['text'],
              rules: true,
              disabled: true
            },
            {
              title: '数量',
              key: 'amount',
              type: ['number'],
              rules: true,
              disabled: true
            },
            {
              title: '单位',
              key: 'unit',
              type: ['text'],
              rules: true,
              disabled: true,
              maxlength: 2
            },
            {
              title: '来源',
              key: 'sourceDisposition',
              type: ['text'],
              disabled: true
            },
            {
              title: '备注',
              key: 'remark',
              type: ['textarea'],
              disabled: true
            },
            {
              title: '附件上传',
              key: 'fileId',
              type: ['file'],
              rules: false,
              disabled: true
            }
          ]
          this.formData.options = options
        }
        this.formData.form = JSON.parse(JSON.stringify(row))
        this.formData.form.occurDate = formatDataB(this.formData.form.occurDate)
      }
    },
    // 修改
    updateDetail(row) {
      // console.log(row, '修改')
      this.titleInfo = '修改'
      this.dialogVisibleTwo = true
      // 查看收入支出
      if (row.module === '收入' || row.module === '支出') {
        if (row.module === '收入') {
          this.creator = 'income'
        }
        if (row.module === '支出') {
          this.creator = 'expenses'
        }
        this.ledgerIdOne = row.ledgerIdOne
        this.ledgerIdTwo = row.ledgerIdTwo
        this.id = row.id
        const details = row.details
        details.amount = row.amount
        details.occurDate = formatDataB(row.occurDate)
        this.fileId = details.fileId
        this.changeFormFieldUpdate(row.ledgerIdOne, row.ledgerIdTwo, this.creator, details)
      }
      // 修改债务债权
      if (row.module === '债务债权') {
        this.creator = 'creditor'
        this.amount = row.amount
        this.currentAmount = row.currentAmount
        if (row.fileId) {
          this.fileId = row.fileId.split(',')
        }
        if (row.flag === -1) {
          const options = [
            {
              title: '发生日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '发生金额(元)',
              key: 'amount',
              type: ['number'],
              rules: true
            }
          ]
          this.formData.options = options
        } else if (row.flag === 1) {
          const options = [
            {
              title: '发生日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '发生原因',
              key: 'reason',
              type: ['text'],
              rules: true
            },
            {
              title: '发生金额(元)',
              key: 'amount',
              type: ['number'],
              rules: true
            }
          ]
          this.formData.options = options
        } else {
          const options = [
            {
              title: '发生日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '相对人',
              key: 'counterparty',
              type: ['text'],
              rules: true
            },
            {
              title: '金额(元)',
              key: 'amount',
              type: ['number'],
              rules: true
            },
            {
              title: '约定收款日期',
              key: 'agreedDate',
              type: ['date', 'direction', 1]
            },
            {
              title: '约定还款日期',
              key: 'agreedDate',
              type: ['date', 'direction', 2]
            },
            {
              title: '发生原因',
              key: 'reason',
              type: ['text']
            },
            {
              title: '附件上传',
              key: 'fileId',
              type: ['file'],
              rules: false
            }
          ]
          this.formData.options = options
        }
        this.formData.form = row
        this.formData.form.occurDate = formatDataB(this.formData.form.occurDate)
        if (this.formData.form.agreedDate) {
          this.formData.form.agreedDate = formatDataB(this.formData.form.agreedDate)
        }
      }
      // 修改库存
      if (row.module === '库存') {
        this.creator = 'stock'
        this.amount = row.amount
        this.currentAmount = row.currentAmount
        if (row.fileId) {
          this.fileId = row.fileId.split(',')
        }
        if (row.flag === -1) {
          const options = [
            {
              title: '出库日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '出库数量',
              key: 'amount',
              type: ['number'],
              rules: true
            },
            {
              title: '出库去向',
              key: 'sourceDisposition',
              type: ['text'],
              rules: true
            }
          ]
          this.formData.options = options
        } else if (row.flag === 1) {
          const options = [
            {
              title: '入库日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '入库数量',
              key: 'amount',
              type: ['number'],
              rules: true
            }
          ]
          this.formData.options = options
        } else {
          const options = [
            {
              title: '日期',
              key: 'occurDate',
              type: ['date'],
              rules: true,
              disabled: true
            },
            {
              title: '名称',
              key: 'name',
              type: ['text'],
              rules: true,
              disabled: true
            },
            {
              title: '数量',
              key: 'amount',
              type: ['number'],
              rules: true
            },
            {
              title: '单位',
              key: 'unit',
              type: ['text'],
              rules: true,
              maxlength: 2
            },
            {
              title: '来源',
              key: 'sourceDisposition',
              type: ['text']
            },
            {
              title: '备注',
              key: 'remark',
              type: ['textarea']
            },
            {
              title: '附件上传',
              key: 'fileId',
              type: ['file'],
              rules: false
            }
          ]
          this.formData.options = options
        }
        this.formData.form = row
        this.formData.form.occurDate = formatDataB(this.formData.form.occurDate)
      }
    },
    // 删除
    deleteDetail(row) {
      // console.log(row, '删除')
      MessageBox.confirm('请确定是否删除该记录', '删除记录', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (row.module === '收入') {
          const params = {
            id: row.id,
            scrap: 1
          }
          deleteIncomeRecord(params).then(res => {
            if (res.code === 0) {
              this.$message.success('删除成功')
              this.searchData()
            }
          })
        } else if (row.module === '支出') {
          const params = {
            id: row.id,
            scrap: 1,
            ledgerIdOne: row.ledgerIdOne,
            ledgerIdTwo: row.ledgerIdTwo
          }
          deleteExpensesRecord(params).then(res => {
            if (res.code === 0) {
              this.$message.success('删除成功')
              this.searchData()
            }
          })
        } else if (row.module === '债务债权') {
          if (row.fileId) {
            row.fileId = row.fileId.toString()
          }
          deleteCreditDebtRecord(row).then(res => {
            if (res.code === 0) {
              this.$message.success('删除成功')
              this.searchData()
            }
          })
        } else if (row.module === '库存') {
          if (row.fileId) {
            row.fileId = row.fileId.toString()
          }
          deleteStockRecord(row).then(res => {
            if (res.code === 0) {
              this.$message.success('删除成功')
              this.searchData()
            }
          })
        }
      })
    },
    // 报废
    scrapDetail(row) {
      // console.log(row, '报废')
      MessageBox.confirm('请确定是否报废该固定资产', '报废固定资产', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        if (row.module === '收入') {
          const params = {
            asset: row.name,
            id: row.id,
            scrap: 0
          }
          deleteIncomeRecord(params).then(res => {
            if (res.code === 0) {
              this.$message.success('报废成功')
              this.searchData()
            }
          })
        } else if (row.module === '支出') {
          const params = {
            asset: row.name,
            id: row.id,
            scrap: 0,
            ledgerIdOne: row.ledgerIdOne,
            ledgerIdTwo: row.ledgerIdTwo
          }
          deleteExpensesRecord(params).then(res => {
            if (res.code === 0) {
              this.$message.success('报废成功')
              this.searchData()
            }
          })
        }
      })
    },
    // 改变form表单字段(查看)
    changeFormField(ledgerIdOne, ledgerIdTwo, creator, form) {
      // console.log(ledgerIdOne, ledgerIdTwo, creator, form, this.$refs)
      // creator: 收入income   支出expenses
      if (creator === 'income') {
        if (ledgerIdOne === 1 && ledgerIdTwo < 1000) { // 销售收入
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.sales))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 2 && ledgerIdTwo < 1000) { // 服务收入
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.serviceIncome))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 3 && ledgerIdTwo < 1000) { // 财政补贴
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.financialSubsidy))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 4 && ledgerIdTwo < 1000) { // 租赁收入
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.rentalIncome))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 5 && ledgerIdTwo < 1000) { // 保险赔付
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.insuranceCompensation))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 6 && ledgerIdTwo === 30 && ledgerIdTwo < 1000) { // 捐赠：资金收入
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.donationIncomeA))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 6 && ledgerIdTwo === 31 && ledgerIdTwo < 1000) { // 捐赠：固定资产
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.donationIncomeB))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 6 && ledgerIdTwo === 32 && ledgerIdTwo < 1000) { // 捐赠：其他物资
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.donationIncomeC))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 7 && ledgerIdTwo < 1000) { // 其他收入
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.otherIncome))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else { // 自定义
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.otherIncome))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        }
      } else if (creator === 'expenses') {
        if (ledgerIdOne === 1 && ledgerIdTwo < 1000) { // 购买农资
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.agriculturalMaterials))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 2 && ledgerIdTwo === 25 && ledgerIdTwo < 1000) { // 固定资产：房屋
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.fixedAssetsA))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 2 && ledgerIdTwo === 26 && ledgerIdTwo < 1000) { // 固定资产：设施设备
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.fixedAssetsB))
          this.formData.form = form
          this.$nextTick(() => {
            // console.log(this.$refs)
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 2 && ledgerIdTwo === 27 && ledgerIdTwo < 1000) { // 固定资产：运输工具
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.fixedAssetsC))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if ((ledgerIdOne === 3 && ledgerIdTwo < 1000) || (ledgerIdOne === 7 && ledgerIdTwo < 1000)) { // 支付工资 && 其他支出
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.payment))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 4 && ledgerIdTwo < 1000) { // 购买保险
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.purchaseInsurance))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 5 && ledgerIdTwo < 1000) { // 支付利息
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.interestPayment))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if ((ledgerIdOne === 6 && ledgerIdTwo === 15 && ledgerIdTwo < 1000) || (ledgerIdOne === 6 && ledgerIdTwo === 17 && ledgerIdTwo < 1000)) { // 支付租金：房屋租金&&设施设备
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.payRentA))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 6 && ledgerIdTwo === 16 && ledgerIdTwo < 1000) { // 支付租金：土地租金
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.payRentB))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else { // 其他
          this.formData = JSON.parse(JSON.stringify(publicDataQuery.otherPay))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        }
      } else {
        return
      }
    },
    // 改变form表单字段(修改)
    changeFormFieldUpdate(ledgerIdOne, ledgerIdTwo, creator, form) {
      // console.log(ledgerIdOne, ledgerIdTwo, creator, form, this.$refs)
      // creator: 收入income   支出expenses
      if (creator === 'income') {
        if (ledgerIdOne === 1 && ledgerIdTwo < 1000) { // 销售收入
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.sales))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 2 && ledgerIdTwo < 1000) { // 服务收入
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.serviceIncome))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 3 && ledgerIdTwo < 1000) { // 财政补贴
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.financialSubsidy))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 4 && ledgerIdTwo < 1000) { // 租赁收入
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.rentalIncome))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 5 && ledgerIdTwo < 1000) { // 保险赔付
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.insuranceCompensation))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 6 && ledgerIdTwo === 30 && ledgerIdTwo < 1000) { // 捐赠：资金收入
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.donationIncomeA))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 6 && ledgerIdTwo === 31 && ledgerIdTwo < 1000) { // 捐赠：固定资产
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.donationIncomeB))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 6 && ledgerIdTwo === 32 && ledgerIdTwo < 1000) { // 捐赠：其他物资
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.donationIncomeC))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 7 && ledgerIdTwo < 1000) { // 其他收入
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.otherIncome))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else { // 自定义
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.otherIncome))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        }
      } else if (creator === 'expenses') {
        if (ledgerIdOne === 1 && ledgerIdTwo < 1000) { // 购买农资
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.agriculturalMaterials))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 2 && ledgerIdTwo === 25 && ledgerIdTwo < 1000) { // 固定资产：房屋
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.fixedAssetsA))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 2 && ledgerIdTwo === 26 && ledgerIdTwo < 1000) { // 固定资产：设施设备
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.fixedAssetsB))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 2 && ledgerIdTwo === 27 && ledgerIdTwo < 1000) { // 固定资产：运输工具
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.fixedAssetsC))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if ((ledgerIdOne === 3 && ledgerIdTwo < 1000) || (ledgerIdOne === 7 && ledgerIdTwo < 1000)) { // 支付工资 && 其他支出
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.payment))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 4 && ledgerIdTwo < 1000) { // 购买保险
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.purchaseInsurance))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 5 && ledgerIdTwo < 1000) { // 支付利息
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.interestPayment))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if ((ledgerIdOne === 6 && ledgerIdTwo === 15 && ledgerIdTwo < 1000) || (ledgerIdOne === 6 && ledgerIdTwo === 17 && ledgerIdTwo < 1000)) { // 支付租金：房屋租金&&设施设备
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.payRentA))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else if (ledgerIdOne === 6 && ledgerIdTwo === 16 && ledgerIdTwo < 1000) { // 支付租金：土地租金
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.payRentB))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        } else { // 其他
          this.formData = JSON.parse(JSON.stringify(publicDataUpdate.otherPay))
          this.formData.form = form
          this.$nextTick(() => {
            this.$refs.form.addRules(this.formData.options)
          })
        }
      } else {
        return
      }
    },
    // 关闭弹窗
    open() {
      this.dialogVisible = false
      this.$emit('updateDate')
    }
  }
}
</script>

<style scoped>
.box_search {
  margin-bottom: 20px;
}
</style>
